package org.luxor.eshop.order.service;

import org.luxor.commons.core.web.data.R;
import org.luxor.eshop.order.entity.dto.CommodityDto;
import org.luxor.eshop.order.entity.dto.DeductInventoryDto;
import org.luxor.eshop.order.service.hystrix.StorageHystrixImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Collection;

/**
 * 远程RPC调用仓储服务
 *
 * @author Mr.Yan  @date: 2020/9/2
 */
@FeignClient(name = "luxor-example-seata-storage", path = "storage/commodity", fallback = StorageHystrixImpl.class)
public interface StorageFeign {

    /**
     * 对给定的商品扣除仓储数量。
     *
     * @param deductInventory 扣除库存请求参数
     * @return 是否扣除成功
     */
    @PostMapping(value = "/deductInventory")
    R deductInventory(@RequestBody Collection<DeductInventoryDto> deductInventory);

    /**
     * 获取商品信息
     *
     * @param commodityCode 商品编号
     * @return 商品信息
     */
    @GetMapping("/{commodityCode}")
    R<CommodityDto> getByCommodityCode(@PathVariable("commodityCode") String commodityCode);
}
